import os
import tqdm
import librosa
import hashlib
import pandas as pd

file_list = []
data_list = []
def get_duration_mp3_and_wav(file_path):
    # 文件夹路径file_path是文件名os自动遍历的
    file_paths = f'./wav2count/{file_path}'
    md5 = hashlib.md5()
    f = open(file_paths,'rb')
    md5.update(f.read())
    f.close()
    MD5 = md5.hexdigest()
    duration = librosa.get_duration(filename=file_paths)
    data_list.append([file_path,duration,MD5])

# 文件夹路径
for a,s,k in os.walk('./wav2count'):
    file_list.append(k)

for i in tqdm.tqdm(file_list[0]):
    get_duration_mp3_and_wav(i)
data = pd.DataFrame(data_list)
datas = data.sort_values([1,2],ascending=False)
# 保存的文件名
datas.to_csv('./wav_result.csv')

